<?php
function refile($path)
{
	$od = opendir($path);
	while($file = readdir($od)){
		if($file == '.' || $file == '..'){
			continue;
		}
		$filename = $path.'/'.$file;
		if(is_dir($filename)){
			refile($filename);
		}else{
			if(strrchr($file, '.') == '.jpg'){
				echo $file.'<br>';
			}
		}
	}
}
refile('./img');